<template>
	<uni-popup ref="popup" :mask-click="false">
		<view class="content">
			<view style="text-align: end;padding: 20rpx;"><text @click="close">关闭</text></view>
			<uni-section title="审批意见" type="line" padding>
				<uni-easyinput type="textarea" v-model="formData.comment" placeholder="请输入审批意见"></uni-easyinput>
			</uni-section>
			<uni-section title="驳回到" type="line" padding>
				<uni-data-select :localdata="options" v-model="formData.targetActivityId" />
			</uni-section>
		</view>
		<view class="btn-contant">
			<view>
				<button @click="submitFormConfirm" type="primary">提交</button>
			</view>
		</view>

		<!-- 退回提示窗-->
		<uni-popup ref="backRef" type="dialog">
			<uni-popup-dialog type="info" cancelText="取消" confirmText="确认" title="提示" content="是否确认退回？"
				@confirm="submitForm"></uni-popup-dialog>
		</uni-popup>
	</uni-popup>
</template>
<script>
	import taskApi from '@/api/workflow/task'
	import {
		toast
	} from '@/utils/common'
	export default {
		props: {
			taskId: String,
			backNodeList: Array,
			sendMessage: Object
		},

		data() {
			return {
				visible: false, // 弹出窗口，true弹出
				loading: false,
				formData: {
					taskId: null,
					targetActivityId: null,
					comment: null,
					sendMessage: {}
				},
				rules: {
					targetActivityId: [{
						required: true,
						message: '请选择驳回目标',
						trigger: 'change'
					}, ]
				},
				options: [], // 驳回目标选项
			}
		},

		watch: {
			async visible(newVal) {
				if (newVal) {
					this.options = []
					this.formData.targetActivityId = this.backNodeList[0].nodeId
					this.backNodeList.forEach(e => {
						this.options.push({
							value: e.nodeId,
							text: e.nodeName
						})
					})
				}
			}
		},

		methods: {
			//打开
			open() {
				this.visible = true
				this.$nextTick(function() {
					this.$refs.popup.open('bottom')
				})
			},
			//关闭
			close() {
				this.$refs.popup.close('bottom')
			},
			//确认提交
			submitFormConfirm(){
				this.$refs.backRef.open('center');			
			},
			// 提交表单数据
			submitForm() {
				this.formData = {
					taskId: this.taskId,
					targetActivityId: this.formData.targetActivityId,
					comment: this.formData.comment,
				}
				//消息提醒
				this.formData.sendMessage = {
					title: this.sendMessage.title,
					type: this.sendMessageType,
					messageContent: this.$store.state.user.name + "驳回了" + this.sendMessage.messageContent
				}
				taskApi.backProcess(this.formData).then(response => {
					if (response.code === 200) {
						toast('提交成功')
						this.close()
						// 事件
						let _this = this
						setTimeout(function() {
							_this.$emit("callBack")
						}, 500);
					}
				})
			}

		}
	}
</script>
<style scoped>
	.content {
		height: 70vh;
		background-color: #fff;
		overflow-y: auto;
	}

	.btn-contant {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: flex-end;
		position: fixed;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		bottom: 0;
		padding: 10rpx;
		z-index: 100;
	}

	uni-button {
		width: 180rpx;
		height: 65rpx;
		line-height: 65rpx;
		font-size: 28rpx;
	}
</style>
